package com.setup.trac.pojo.condition;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.setup.trac.pojo.Progetti;
import com.setup.trac.pojo.Utenti;
import com.setup.trac.util.SQLCondition;

public class FindTicketByStatoOrProject extends TicketsFinderByProgettiUtenteAndStatoApertoInCarico{

	private String idStato;
	private String idProject;
	private String idCliente;
	private String idOwner;


	public FindTicketByStatoOrProject(String idProject, String idStato,String idOwner, String idCliente, Utenti utente) {
		super(utente);
		this.idProject = idProject;
		this.idStato = idStato;
		this.idOwner = idOwner;
		this.idCliente = idCliente;
	}

	public Criterion create(Object... params) {
		Criterion result = null;
        Criterion crtPrj = null;
        Criterion crtStati = null;
        if(idProject!=null && !"-1".equals(idProject)){
        	crtPrj = Restrictions.eq("idProgetto", new BigDecimal(idProject));
        }else{
        	crtPrj = getProgettiCriterions();
        }
        if(idStato!=null && !"-1".equals(idStato)){
        	crtStati = Restrictions.eq("stati.idStato", new BigDecimal(idStato));
        	
        }
        if(crtStati==null && crtPrj!=null){
        	return crtPrj;
        }
        if(crtStati!=null && crtPrj==null){
        	return crtStati;
        }
		result = Restrictions.and(crtPrj, crtStati);
		return result;
	}

}
